package com.richfit.barcodesystem_cczt.activitis.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.richfit.barcodesystem_cczt.activitis.model.login.BottomMenuEntity;
import com.richfit.barcodesystem_cczt.databinding.ItemDialogBottomMenuBinding;

import java.util.List;

public class BottomDialogMenuAdapter extends BaseAdapter {
    private ItemDialogBottomMenuBinding binding;
    private Context mContext;
    private List<BottomMenuEntity> list;

    public BottomDialogMenuAdapter(Context context, List<BottomMenuEntity> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public BottomMenuEntity getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if (view == null) {
            binding = ItemDialogBottomMenuBinding.inflate(LayoutInflater.from(mContext));
            view = binding.getRoot();
            view.setTag(binding);
        } else {
            binding = (ItemDialogBottomMenuBinding) view.getTag();
        }
        binding.menuTv.setText(getItem(position).getMenuName());
        binding.menuIv.setBackgroundResource(getItem(position).getMenuImageRes());
        return view;
    }
}
